/**
 * vue
 */
import Vue from 'vue';
require('./bootstrap');
window.Vue = require('vue');

/**
 * vue-router
 */
import VueRouter from 'vue-router';
Vue.use(VueRouter);
import routes from './routers';
const router = new VueRouter({routes});
Vue.component('app-page', require('./components/App').default);

/**
 * vuex
 */
import store from './store'; //vuex

/**
 * element-ui
 */
import ElementUI from 'element-ui';//element
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI, {
    size: 'small'
});

/**
 * 富文本编辑器
 */
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
import VueQuillEditor from "vue-quill-editor";
Vue.use(VueQuillEditor);


/**
 * 手动引入的公用方法
 */
import {get, post} from './utils/request';//封装请求
Vue.prototype.get = get;
Vue.prototype.post = post;
Vue.prototype.$axios = axios;

// 深拷贝
Vue.prototype.deepCopy = function (obj, cache = []) {
    // typeof [] => 'object'
    // typeof {} => 'object'
    if (obj === null || typeof obj !== 'object') {
        return obj
    }
    // 如果传入的对象与缓存的相等, 则递归结束, 这样防止循环
    const hit = cache.filter(c => c.original === obj)[0];
    if (hit) {
        return hit.copy
    }
    const copy = Array.isArray(obj) ? [] : {};
    // 将copy首先放入cache, 因为我们需要在递归deepCopy的时候引用它
    cache.push({
        original: obj,
        copy
    });
    let that = this;
    Object.keys(obj).forEach(key => {
        copy[key] = that.deepCopy(obj[key], cache);
    });
    return copy;
};

new Vue({
    router,
    store,
}).$mount('#app');
